using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Drawing;
using Umdf.SideShow.Scf.Contents;

namespace Umdf.SideShow.Contents
{
    class ContentFactory
    {
        
        public static Content Create(uint id, byte[] data)
        {
            if (id == 0)
            {
                string text = Encoding.UTF8.GetString(data, 0, data.Length);
                return new GlanceContent(text);
            }

            try
            {
                XmlDocument scfDoc = new XmlDocument();
                using (MemoryStream ms = new MemoryStream(data))
                {
                    scfDoc.Load(ms);
                    return new ScfContent(id, scfDoc);
                }
            }
            catch
            {
                try
                {
                    using (MemoryStream ms = new MemoryStream(data))
                    {
                        Image img = new Bitmap(ms);
                        return new ImageContent(id, img);
                    }
                }
                catch
                {
                    return new UnknownContent(id, data);
                }
            }
        }
    }
}
